package dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import model.Emocao;

public class EmocaoDAO {
	
	private Connection conexao;
	private Statement st;
	private ResultSet rs;
	Adaptador adaptador = new Adaptador();
	
	public ArrayList<Emocao> listar() throws SQLException{
		ArrayList<Emocao> emocoes = new ArrayList<Emocao>();
		conexao = adaptador.abrirConexao();
		String sql = "SELECT * FROM Emocao";
		try{
			st = conexao.createStatement();
			rs = st.executeQuery(sql);
			while(rs.next()){
				String nome = rs.getString("nome_emocao");
				int codigo = Integer.parseInt(rs.getString("codigo"));
				Emocao now = new Emocao(nome);
				now.setCodigo(codigo);
				emocoes.add(now);
			}
			
		}catch(SQLException sqle){
			sqle.getMessage();
		}finally{
			conexao.close();
			st.close();
			rs.close();
		}
		return emocoes;
	}

}
